---
title: Prefer Void Public Cubit Methods
description: The prefer_void_public_cubit_methods rule.
---

import { Badge } from '@astrojs/starlight/components';
import EnableRuleSnippet from '~/components/lint-rules/EnableRuleSnippet.astro';
import BadSnippet from '~/components/lint-rules/prefer_void_public_cubit_methods/BadSnippet.mdx';
import GoodSnippet from '~/components/lint-rules/prefer_void_public_cubit_methods/GoodSnippet.astro';

<div class="badges">
	<Badge text="new" />
	<Badge text="dart" variant="note" />
	<Badge text="recommended" variant="success" />
</div>

Prefer void public methods on `Cubit` instances.

:::note

This lint rule was introduced in version `0.2.0-dev.2` of
[`package:bloc_lint`](https://pub.dev/packages/bloc_lint)

:::

## Rationale

Public methods on `Cubit` instances should be used to notify the `Cubit` and
initiate state changes via the `emit` method. If the caller needs access to any
state information, they should access it from the `state` instead.

:::note

The following rules are related and are usually enabled in combination with
`prefer_void_public_cubit_methods`.

- [`avoid_public_bloc_methods`](/lint-rules/avoid_public_bloc_methods)
- [`avoid_public_fields`](/lint-rules/avoid_public_fields)

:::

## Examples

**Avoid** non-void public methods on `Cubit` instances.

**BAD**:

<BadSnippet />

**GOOD**:

<GoodSnippet />

## Enable

To enable the `prefer_void_public_cubit_methods` rule, add it to your
`analysis_options.yaml` under `bloc` > `rules`:

<EnableRuleSnippet name="prefer_void_public_cubit_methods" />
